package com.ruoyi.web.controller.agent;

import com.ruoyi.agent.domain.AmAgent;
import com.ruoyi.agent.service.IAmAgentService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 经纪人信息Controller
 * 
 * @author ruoyi
 * @date 2020-07-26
 */
@RestController
@RequestMapping("/agent/agent")
@Api(description = "经纪人管理")
public class AmAgentController extends BaseController
{
    @Autowired
    private IAmAgentService amAgentService;

    /**
     * 查询经纪人信息列表
     */
    @PreAuthorize("@ss.hasPermi('agent:agent:list')")
    @GetMapping("/list")
    @ApiOperation("查询经纪人信息列表")
    public TableDataInfo list(AmAgent amAgent)
    {
        startPage();
        List<AmAgent> list = amAgentService.selectAmAgentList(amAgent);
        return getDataTable(list);
    }


    /**
     * 经纪人层级关系
     */
    @GetMapping("/load/{id}")
    @ApiOperation("经纪人层级关系")
    public AjaxResult load(@PathVariable Long id)
    {
        return AjaxResult.success(amAgentService.load(id));
    }
    /**
     * 导出经纪人信息列表
     */
    @PreAuthorize("@ss.hasPermi('agent:agent:export')")
    @Log(title = "经纪人信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出经纪人信息列表")
    public AjaxResult export(AmAgent amAgent)
    {
        List<AmAgent> list = amAgentService.selectAmAgentList(amAgent);
        ExcelUtil<AmAgent> util = new ExcelUtil<AmAgent>(AmAgent.class);
        return util.exportExcel(list, "agent");
    }

    /**
     * 获取经纪人信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('agent:agent:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取经纪人信息详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(amAgentService.selectAmAgentById(id));
    }


    /**
     * 新增经纪人信息
     */
    @PreAuthorize("@ss.hasPermi('agent:agent:add')")
    @Log(title = "经纪人信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增经纪人信息")
    public AjaxResult add(@RequestBody AmAgent amAgent)
    {
        return toAjax(amAgentService.insertAmAgent(amAgent));
    }

    /**
     * 修改经纪人信息
     */
    @PreAuthorize("@ss.hasPermi('agent:agent:edit')")
    @Log(title = "经纪人信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改经纪人信息")
    public AjaxResult edit(@RequestBody AmAgent amAgent)
    {
        return toAjax(amAgentService.updateAmAgent(amAgent));
    }

    /**
     * 删除经纪人信息
     */
    @PreAuthorize("@ss.hasPermi('agent:agent:remove')")
    @Log(title = "经纪人信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除经纪人信息")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(amAgentService.deleteAmAgentByIds(ids));
    }



}
